using System.Collections.Generic;
using PPI.Client.Interface;
using PPI.Client.Logic.Inspection;
using PPI.Client.Logic.Utility;
using PPI.Entities;
using PPI.Entities.Inspections;
using PPI.Entities.Utility;

namespace PPI.Client.Presenter
{
    public class FilterBrowserPresenter
    {
        private IFilterBrowser m_View;

        public FilterBrowserPresenter(IFilterBrowser m_View)
        {
            this.m_View = m_View;
        }

        public void Search()
        {
            m_View.SelectedVisit = null;

            switch (m_View.VisitType)
            {
                case "GPS Structure":
                    List<EVendor_Visit_XMissionStructure> tmpListVendor = PPI.Client.Logic.LVendor_Visit_XMissionStructure.GetMobileProject(m_View.SelectedId, m_View.ConnectionString);
                    if (tmpListVendor.Count == 1)
                        m_View.SelectedVisit = tmpListVendor[0];
                    break;
                case "GPS Pole":
                    List<EVendor_Visit_XMissionStructure> tmpListVendorPole = PPI.Client.Logic.LVendor_Visit_XMissionStructure.GetMobileProjectByPole(m_View.SelectedId, m_View.ConnectionString);
                    if (tmpListVendorPole.Count == 1)
                        m_View.SelectedVisit = tmpListVendorPole[0];
                    break;
                case "Inspection Structure":
                    List<EInspectionStructure> tmpListStructures = LInspectionStructure.LoadProjectStructures(m_View.SelectedId, m_View.ConnectionString);
                    if (tmpListStructures.Count == 1)
                        m_View.SelectedVisit = tmpListStructures[0];
                    break;
                case "Inspection Pole":
                    List<EInspectionStructure> tmpListStructuresByPole = LInspectionStructure.LoadProjectStructuresByPole(m_View.SelectedId, m_View.ConnectionString);
                    if (tmpListStructuresByPole.Count == 1)
                        m_View.SelectedVisit = tmpListStructuresByPole[0];
                    break;
                    break;
                case "Asset":
                    List<EUtility_Asset_XMissionStructure> tmpListAssets = LUtility_Asset_XMissionStructure.SelectAllWithInspectionGps(m_View.SelectedId, m_View.ConnectionString);
                    if (tmpListAssets.Count == 1)
                        m_View.SelectedVisit = tmpListAssets[0];
                    break;
            }

            if (m_View.SelectedVisit != null && m_View.SelectedOffice != null)
            {
                m_View.Direction = Constants.K_GoogleMapDirectionsWEB;
                m_View.Direction = m_View.Direction.Replace("KML_DEST_ADDRESS", m_View.SelectedVisit.GetAddress());
                m_View.Direction = m_View.Direction.Replace("KML_SOURCE_ADDRESS", m_View.SelectedOffice.GetAddress().Replace(" ", "+"));
            }

        }
    }
}